package org.javaforever.gatescore.reports;

import java.util.List;

import org.javaforever.gatescore.core.FrontDomain;
import org.javaforever.gatescore.core.FrontField;
import org.javaforever.gatescore.core.Statement;
import org.javaforever.gatescore.core.StatementList;
import org.javaforever.gatescore.core.ValidateInfo;
import org.javaforever.gatescore.core.WriteableUtil;

public class EChartsCompareGridReport extends ReportComb{
	private static final long serialVersionUID = 1L;
	protected EchartsCompareGridReportLayout eLayout = new EchartsCompareGridReportLayout();
	protected FrontDomain  planDomain;
	protected FrontDomain actionDomain;
	protected List<FrontField> planxAxisFields;
	protected FrontField planyName;
	protected List<FrontField> actionxAxisFields;
	protected FrontField actionyName;
	
	public EChartsCompareGridReport() {
		super();
	}
	
	public EChartsCompareGridReport(FrontDomain planDomain,List<FrontField> planxAxisFields,FrontField planyName,FrontDomain actionDomain,List<FrontField> actionxAxisFields,FrontField actionyName) throws Exception {
		super();
		this.standardName = "EchartsCompareGridReport"+planDomain.getCapFirstDomainName()+actionDomain.getCapFirstDomainName();
		this.label = planDomain.getText()+ actionDomain.getText() +"Echarts比较网格图表";
		if ("english".equalsIgnoreCase(planDomain.getLanguage())) {
			this.label ="Echarts Compare Grid Report for"+planDomain.getText() +" and " +actionDomain.getText();
		}
		this.planDomain = planDomain;
		this.planxAxisFields = planxAxisFields;
		this.planyName = planyName;
		this.actionDomain = actionDomain;
		this.actionxAxisFields = actionxAxisFields;
		this.actionyName = actionyName;
		
		this.domains.add(this.planDomain);
		this.domains.add(this.actionDomain);
		
		eLayout.setPlanDomain(this.planDomain);
		eLayout.setPlanxAxisFields(this.planxAxisFields);
		eLayout.setPlanyName(this.planyName);
		
		eLayout.setActionDomain(this.actionDomain);
		eLayout.setActionxAxisFields(this.actionxAxisFields);
		eLayout.setActionyName(this.actionyName);
		
		eLayout.parse();
	}

	public FrontDomain getPlanDomain() {
		return planDomain;
	}

	public void setPlanDomain(FrontDomain planDomain) {
		this.planDomain = planDomain;
	}

	public FrontDomain getActionDomain() {
		return actionDomain;
	}

	public void setActionDomain(FrontDomain actionDomain) {
		this.actionDomain = actionDomain;
	}

	@Override
	public void generateCombFiles(String targetFolderPath) throws Exception {
		String relativeFolder = "src/views/pages/";
		WriteableUtil.writeToFile(targetFolderPath + "/"+relativeFolder+this.standardName.toLowerCase()+".vue", this.eLayout.generateStatements().getContent());
	}

	@Override
	public void generateCombFromDomians() throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public ValidateInfo validateDomains() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean validateVerbs() throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean validateLayouts() throws Exception {
		// TODO Auto-generated method stub
		return false;
	}

	public List<FrontField> getPlanxAxisFields() {
		return planxAxisFields;
	}

	public void setPlanxAxisFields(List<FrontField> planxAxisFields) {
		this.planxAxisFields = planxAxisFields;
	}

	public FrontField getPlanyName() {
		return planyName;
	}

	public void setPlanyName(FrontField planyName) {
		this.planyName = planyName;
	}

	public List<FrontField> getActionxAxisFields() {
		return actionxAxisFields;
	}

	public void setActionxAxisFields(List<FrontField> actionxAxisFields) {
		this.actionxAxisFields = actionxAxisFields;
	}

	public FrontField getActionyName() {
		return actionyName;
	}

	public void setActionyName(FrontField actionyName) {
		this.actionyName = actionyName;
	}
	
	public String getPlanxAxisFieldsNames() {
		if (this.planxAxisFields==null||this.planxAxisFields.size()==0) return "";
		StringBuilder sb = new StringBuilder();
		for (FrontField f:this.planxAxisFields) {
			sb.append(f.getFieldName()).append(",");
		}
		String result = sb.toString();
		if (result.endsWith(",")) result = result.substring(0,result.lastIndexOf(","));
		return result;
	}
	
	public String getActionxAxisFieldsNames() {
		if (this.actionxAxisFields==null||this.actionxAxisFields.size()==0) return "";
		StringBuilder sb = new StringBuilder();
		for (FrontField f:this.actionxAxisFields) {
			sb.append(f.getFieldName()).append(",");
		}
		String result = sb.toString();
		if (result.endsWith(",")) result = result.substring(0,result.lastIndexOf(","));
		return result;
	}
	
	@Override
	public String getDomainNamesStr() {
		return this.planDomain.getStandardName()+","+this.actionDomain.getStandardName();
	}
}
